package com.XinYun.Library.modules.commons.ResponseWrapper;

import com.XinYun.Library.modules.commons.ReturnCodes.Impl.ReturnCodes;

public class ResponseWrapper {
    private String code;
    private String msg;
    private Object data;

    public ResponseWrapper() {
    }

    public ResponseWrapper(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseWrapper{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    /**
     * 成功而且得返回数据（如借阅书籍次数，还书次数等等）
     * @param data 传入要返回的数据
     * @return 返回响应对象
     */
    public static ResponseWrapper Success(Object data){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.SUCCESS.getCode());
        responseWrapper.setMsg(ReturnCodes.SUCCESS.getMsg());
        responseWrapper.setData(data);
        return responseWrapper;
    }

    /**
     * 成功但无数据可返回（验证成功，注册成功，登录成功）
     * @return 返回响应对象
     */
    public static ResponseWrapper NoData(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.NODATA.getCode());
        responseWrapper.setMsg(ReturnCodes.NODATA.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 用户登陆成功
     * @return 返回响应对象
     */
    public static ResponseWrapper UserSuccess(String token){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.USER_SUCCESS.getCode());
        responseWrapper.setMsg(ReturnCodes.USER_SUCCESS.getMsg());
        responseWrapper.setData(token);
        return responseWrapper;
    }

    /**
     * 管理员登陆成功
     * @return 返回响应对象
     */
    public static ResponseWrapper AdminSuccess(String token){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.ADMIN_SUCCESS.getCode());
        responseWrapper.setMsg(ReturnCodes.ADMIN_SUCCESS.getMsg());
        responseWrapper.setData(token);
        return responseWrapper;
    }

    /**
     * 邮件发送成功
     * @return 返回响应对象
     */
    public static ResponseWrapper SendSuccess(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.SEND_SUCCESS.getCode());
        responseWrapper.setMsg(ReturnCodes.SEND_SUCCESS.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 重置密码成功
     * @return 返回响应对象
     */
    public static ResponseWrapper ResetSuccess(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.RESET_SUCCESS.getCode());
        responseWrapper.setMsg(ReturnCodes.RESET_SUCCESS.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }
    /**
     * 失败（包括各种失败）
     * @return 返回响应对象
     */
    public static ResponseWrapper Fail(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.FAILURE.getCode());
        responseWrapper.setMsg(ReturnCodes.FAILURE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 账号不存在
     * @return 返回响应对象
     */
    public static ResponseWrapper AccountFail(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.ACCOUNT_FAILURE.getCode());
        responseWrapper.setMsg(ReturnCodes.ACCOUNT_FAILURE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 密码与账号不匹配
     * @return 返回响应对象
     */
    public static ResponseWrapper PasswordFail(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.PASSWORD_FAILURE.getCode());
        responseWrapper.setMsg(ReturnCodes.PASSWORD_FAILURE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 学号已被注册，无法重复注册
     * @return 返回响应对象
     */
    public static ResponseWrapper ExistFail(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.EXIST_FAILURE.getCode());
        responseWrapper.setMsg(ReturnCodes.EXIST_FAILURE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 该同学并非书院内部人员，无法注册
     * @return 返回响应对象
     */
    public static ResponseWrapper MemberFail(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.MEMBER_FAILURE.getCode());
        responseWrapper.setMsg(ReturnCodes.MEMBER_FAILURE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 邀请码错误，注册失败
     * @return 返回响应对象
     */
    public static ResponseWrapper InviteFail(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.INVITE_FAILURE.getCode());
        responseWrapper.setMsg(ReturnCodes.INVITE_FAILURE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 邮箱格式错误，无法注册
     * @return 返回响应对象
     */
    public static ResponseWrapper MailFail(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.MAIL_FAILURE.getCode());
        responseWrapper.setMsg(ReturnCodes.MAIL_FAILURE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 用户学号与邮箱不匹配，请重新输入
     * @return 返回响应对象
     */
    public static ResponseWrapper SuitFail(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.SUIT_FAILURE.getCode());
        responseWrapper.setMsg(ReturnCodes.SUIT_FAILURE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 用户两次输入的密码不一致，请重新输入
     * @return 返回响应对象
     */
    public static ResponseWrapper CopyFail(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.COPY_FAILURE.getCode());
        responseWrapper.setMsg(ReturnCodes.COPY_FAILURE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 用户输入的验证码与获取的验证码不匹配，请重新输入
     * @return 返回响应对象
     */
    public static ResponseWrapper CodeFail(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.CODE_FAILURE.getCode());
        responseWrapper.setMsg(ReturnCodes.CODE_FAILURE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 查询不到书籍
     * @return 返回响应对象
     */
    public static ResponseWrapper UnKnowbook(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ReturnCodes.ERR_UNKNOWN_STATE.getCode());
        responseWrapper.setMsg(ReturnCodes.ERR_UNKNOWN_STATE.getMsg());
        responseWrapper.setData(null);
        return responseWrapper;
    }
}

